import { NextResponse } from 'next/server'
import prisma from '@/lib/prisma'

export async function POST(req: Request): Promise<Response> {
  try {
    const { copies } = await req.json()
    console.log(copies)

    // 批量更新话题的排序值
    const updatePromises = copies.map((topic: any) => {
      const { id, pxh,topic_id } = topic
      return prisma.vms_copy.update({
        where: { id },
        data: { topic_id,pxh },
      })
    })

    await Promise.all(updatePromises)

    return NextResponse.json({ success: true })
  } catch (error) {
    console.error('更新文案排序失败:', error)
    return NextResponse.json(
      { error: '更新文案排序失败' },
      { status: 500 }
    )
  }
}
